#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#define OJ_TEST 0
#define LOCAL_TEST 0

#define M 901

static int max(int a, int b){ return a>b?a:b; }
static int min(int a, int b) { return a<b?a:b; }

static void solve(void){
	int cs;
	int a, b, c;
	int i, n;
	long long ans;
	for(scanf("%d", &cs); cs>0; --cs){
		scanf("%d", &n);
		ans = 0;
		for(i=0; i<n; ++i){
			scanf("%d%d%d", &a, &b, &c);
			ans += (long long)a*c;
		}
		printf("%lld\n", ans);
	}

}
#if OJ_TEST
	int main(int ac, char *av[]){
		solve();
		return 0;
	}
#elif  LOCAL_TEST
	void run(void){
		solve();
	}

#else

#endif
